package sg.edu.nus.iss.club.gui.util;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

import sg.edu.nus.iss.club.gui.ClubApplication;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public abstract class OkCancelDialog extends JDialog {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	protected JButton cancelButton;
	protected JButton okButton;
	public ClubApplication clubApplication;
	
	/*
	 * This is Daniel way of doing but it is sucks as I do not make use of those layout to
	 * dynamic create of components.
	 * Lecturer design is using the borderlayout with proper define of MainFormPanel and
	 * ButtonPanel whereby the ButtonPanel will be created at superclass level while
	 * MainFormPanel created at subclass level
	protected abstract class ButtonActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			actionMethod(e);
			setVisible(false);
			dispose();
		}
		
		protected abstract void actionMethod(ActionEvent e);
	}
	
	protected class CancelButtonActionListener extends ButtonActionListener {
		protected void actionMethod(ActionEvent e) {}
	}
	*/
	
	public OkCancelDialog(JFrame parent) {
		super(parent);
	}
	
	public OkCancelDialog(JFrame frame, String title) {
		super(frame, title);
		setSize(350, 150);
		setLocation(200, 200);
		add ("Center", createFormPanel());
        add ("South",  createButtonPanel());
	}
	
	private JPanel createButtonPanel() {
		JPanel p = new JPanel();

		Button b;
		ActionListener l;

		b = new Button("OK");
		l = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean success = performOkAction();
				if (success) {
					destroyDialog();
				}
			}
		};
		b.addActionListener(l);
		p.add(b);

		b = new Button("Cancel");
		l = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				destroyDialog();
			}
		};
		b.addActionListener(l);
		p.add(b);

		return p;
	}

	private void destroyDialog() {
		setVisible(false);
		dispose();
	}

	protected abstract JPanel createFormPanel();

	protected abstract boolean performOkAction();
	
}
